package at.sysarch.filter;

import java.awt.image.renderable.ParameterBlock;

import javax.media.jai.JAI;
import javax.media.jai.operator.MedianFilterDescriptor;
import javax.media.jai.operator.MedianFilterShape;

import at.pimpmypipe.filter.DataEnrichmentFilter;
import at.sysarch.bean.AbstractBean;
import at.sysarch.domain.TransferImage;

public class MedianFilter extends DataEnrichmentFilter<TransferImage, TransferImage> {
	
	public MedianFilter(AbstractBean<MedianFilter> bean) {
		super(bean);
	}
	
	private int _maskSize = 10;
	private MedianFilterShape _maskShape = MedianFilterDescriptor.MEDIAN_MASK_SQUARE;

	@Override
	protected boolean fillEntity(TransferImage nextVal, TransferImage entity) {
		
		entity.setSourceImage(nextVal.getSourceImage());
		
		ParameterBlock medianParams = new ParameterBlock();
		
		medianParams.addSource(nextVal.getModifiedImage());
		medianParams.add(_maskShape);
		medianParams.add(_maskSize);
		

		entity.setModifiedImage(JAI.create("MedianFilter", medianParams));
		_bean.displayImage(entity);
		return true;
	}

	@Override
	protected TransferImage getNewEntityObject() {

		return new TransferImage();
	}

	public void setMaskSize(int maskSize) {
		
		_maskSize = maskSize;
	}
	
	public int getMaskSize() {
		return _maskSize;
	}
	
	public void setMaskShape(MedianFilterShape maskShape) {
		
		_maskShape = maskShape;
	}
	
	public MedianFilterShape getMaskShape() {
		
		return _maskShape;
	}
}
